package com.taru.university.controller;

import com.taru.university.utils.Constant;
import com.taru.university.utils.JsonResult;
import com.taru.university.model.Analise;
import com.taru.university.service.AnaliseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@CrossOrigin
public class AnaliseController {
    private static Logger logger = LoggerFactory.getLogger(AnaliseController.class);
    @Autowired
    AnaliseService analiseService;
    /**
     * 根据userId和数据批次号查询结果
     * @param userId
     * @param dataBatchNumber
     * @return
     */
    @RequestMapping("/query/anasile/result")
    @ResponseBody
    public Object queryAnaliseResult(String userId,String dataBatchNumber){
        JsonResult result = null;
        try{
            Analise analise = analiseService.queryAnaliseResult(userId,dataBatchNumber);
            logger.info("用户Id：{},数据批次号{}",userId,dataBatchNumber);
            result = new JsonResult("查询成功", Constant.STATUC_SUCCESS,analise);
        }catch (Exception ex){
            logger.info(ex.getMessage());
            result = new JsonResult("查询异常", Constant.STATUC_FAILURE);
        }
        return result;
    }

    /**
     * 插入结果
     * @param analise
     */
    @RequestMapping("/insert/anasile/result")
    @ResponseBody
    public Object insertAnaliseResult(Analise analise){
        JsonResult result = null;
        try {
            analiseService.insertAnaliseResult(analise);
            logger.info("结果数据：{}",analise);
            result = new JsonResult("添加成功",Constant.STATUC_FAILURE);
        }catch (Exception ex){
            logger.info(ex.getMessage());
            result = new JsonResult("添加异常",Constant.STATUC_FAILURE);
        }
        return result;
    }

    /**
     * 删除结果
     * @param userId
     * @param dataBatchNumber
     */
    @RequestMapping("/delete/anasile/result")
    @ResponseBody
    public Object deletetAnaliseResult(String userId,String dataBatchNumber){
        JsonResult result = null;
        try {
            analiseService.deletetAnaliseResult(userId,dataBatchNumber);
            logger.info("用户Id：{},数据批次号{}",userId,dataBatchNumber);
            result = new JsonResult("删除成功",Constant.STATUC_FAILURE);
        }catch (Exception ex){
            logger.info(ex.getMessage());
            result = new JsonResult("删除异常",Constant.STATUC_FAILURE);
        }
        return result;
    }
}
